package com.gisocn.onemap.base;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.os.EnvironmentCompat;
import com.gisocn.onemap.base.BasePresenter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/* loaded from: classes.dex */
public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity {
    protected Activity mActivity;
    protected Context mContext;
    protected P presenter;
    public ProgressDialog progressDialog;

    protected abstract P createPresenter();

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        this.presenter = createPresenter();
        super.onCreate(bundle);
        this.mContext = this;
        this.mActivity = this;
        disableAPIDialog();
    }

    public void setStatusBar(int i) {
        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().getDecorView().setSystemUiVisibility(1280);
            getWindow().setStatusBarColor(i);
        }
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        P p = this.presenter;
        if (p != null) {
            p.detachView();
        }
    }

    public String getDeviceId() {
        String string = Settings.System.getString(getContentResolver(), "android_id");
        if (string == null && ((string = Build.SERIAL) == null || string.equals(EnvironmentCompat.MEDIA_UNKNOWN))) {
            string = null;
        }
        Log.e("deviceId", string);
        return string;
    }

    public void showToast(String str) {
        Toast.makeText(this, str, 0).show();
    }

    public String getStr(EditText editText) {
        return editText.getText().toString().trim();
    }

    public String getStr(TextView textView) {
        return textView.getText().toString().trim();
    }

    public boolean isNull(String str) {
        return str == null || "".equals(str) || "null".equalsIgnoreCase(str);
    }

    public boolean isNull(EditText editText) {
        return editText.getText().toString() == null || "".equals(editText.getText().toString().trim()) || "null".equalsIgnoreCase(editText.getText().toString().trim());
    }

    public void showLoading() {
        showProgressDialog();
    }

    public void hideLoading() {
        dismissProgressDialog();
    }

    public ProgressDialog showProgressDialog() {
        ProgressDialog progressDialog = new ProgressDialog(this);
        this.progressDialog = progressDialog;
        progressDialog.setMessage("加载中");
        this.progressDialog.show();
        return this.progressDialog;
    }

    public ProgressDialog showProgressDialog(CharSequence charSequence) {
        ProgressDialog progressDialog = new ProgressDialog(this);
        this.progressDialog = progressDialog;
        progressDialog.setMessage(charSequence);
        this.progressDialog.show();
        return this.progressDialog;
    }

    public void dismissProgressDialog() {
        ProgressDialog progressDialog = this.progressDialog;
        if (progressDialog == null || !progressDialog.isShowing()) {
            return;
        }
        this.progressDialog.dismiss();
    }

    private void disableAPIDialog() {
        if (Build.VERSION.SDK_INT < 28) {
            return;
        }
        try {
            Class<?> cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread", new Class[0]);
            declaredMethod.setAccessible(true);
            Object invoke = declaredMethod.invoke(null, new Object[0]);
            Field declaredField = cls.getDeclaredField("mHiddenApiWarningShown");
            declaredField.setAccessible(true);
            declaredField.setBoolean(invoke, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
